<template>
  <div>
    <a-modal v-model="visible" title="删款" :width="900" centered okText="确认删款" @ok="handleSubmit" destroyOnClose class="return-modal">
      <p class="tip">温馨提示：发货后商品不允许删除!</p>
      <GoodsTable :tableData="data" :tableType="'delete'" @handleSelect="handleSelect"></GoodsTable>
    </a-modal>
  </div>
</template>
<script>
import GoodsTable from './goodsTable'
import { delBoxDetails, getDelBoxDetailsInWait } from '@/api/box/order'
export default {
  components: {
    GoodsTable
  },
  data() {
    return {
      visible: false,
      data: [],
      boxId: '',
      pickIds: []
    }
  },
  methods: {
    show(id) {
      this.boxId = id
      this.data = []
      this.fetchData()
    },
    fetchData() {
      let params = {
        requestData: {
          boxId: this.boxId
        }
      }
      getDelBoxDetailsInWait(params).then(res => {
        if (res.code == 0) {
          this.data = res.data
          this.visible = true
        } else {
          this.$message.warning(res.msg)
        }
      })
    },
    handleSelect(data) {
      // console.log(selectedRowKeys, selectedRows)
      this.pickIds = data
    },
    handleSubmit() {
      if (this.pickIds.length > 0) {
        let params = {
          requestData: {
            boxDetailId: this.pickIds,
            boxId: this.boxId
          }
        }
        delBoxDetails(params).then(res => {
          if (res.code == 0) {
            this.$message.success('删除成功！')
            this.$emit('updateTable')
            this.visible = false
          } else {
            this.$message.warning(res.msg)
          }
        })
      } else {
        this.$message.warning('请选择商品进行删款')
      }
    }
  }
}
</script>
<style src="../less/modal.less" lang="less" scoped></style>

